#!/usr/bin/env node

const inquirer = require('inquirer')
const path = require('path');
const fs = require('fs')
const ejs = require('ejs')

inquirer.prompt([
    {
        type: 'input',
        name: 'name',
        message: 'Project name is?'
    }
])
    .then(anwsers => {
        // console.log(anwsers);
        // 模板路径
        const tempDir = path.join(__dirname, 'temp')
        // 目标路径
        const distDir = process.cwd()

        fs.readdir(tempDir, (err, files) => {
            if (err) throw err
            files.forEach((fileWay) => {
                ejs.renderFile(path.join(tempDir,fileWay),anwsers,(err, resolve) => {
                    if (err) throw err
                    fs.writeFileSync(path.join(distDir,fileWay), resolve)
                })
            })
            console.log('模板创建成功');
        })
    })